package com.smart.web.controller.user.weiliao.controller;

import com.smart.common.core.domain.R;
import com.smart.system.domain.Employee;
import com.smart.system.domain.dto.SensorDataWrapperDto;
import com.smart.system.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;
import java.util.List;

@RestController
@RequestMapping("/test")
public class Test {
    @Autowired
    private IEmployeeService employeeService;

    @PostMapping("upData")
    public void upData(@RequestBody SensorDataWrapperDto dto){
        System.err.println(dto.toString());
    }

    @GetMapping("getUser")
    public List<Employee> getUser(){
        return employeeService.list();
    }

    @GetMapping("getUserById")
    public R<Employee> getUserById(String userId){
        return R.ok(employeeService.getById(userId));
    }

    public static void main(String[] args) throws Exception {
        String encodedText = "您的Base64密文";
        byte[] decodedBytes = Base64.getDecoder().decode(encodedText);

        // 假设是 AES-128 加密（需替换为实际密钥）
        String key = "WuEZliaDUzPGhPnBobgD5BS4Bk0QoriKHn2ARMT3TsuSPGel4ee2A/VEP3QMTn6xCbziHTHpK/VxNHBEQV9nEO1NINeDAonsfxpy13uEdHmBRJ23Ei6IGF10n/7D86ec0rnhgNfHfD8SxSurEY/sA9oMMRrNBWAtodCkMznGZ3g+t0TtGdyMgUvpBXCSJcfn739JeQZ454mL4UBENlL3aFzAzLIqbVtgqh7mWWYgo4/ukiNa52qfm3oBpTf7V7YA/UP5CsQKT3g9x8MDFEnpe6R4Y0eHtZyGT3psCiuXmT+qJiO9smw8qf6nscX7yd1jqFJq7MUefRa/cdo9kHvPvS3p/PRZ6nZxwS9uXZieLrQifGlces0cv5aWFo6JprlMXB5ohLhDBscf5Revx/ivOUkSiYI5BqtLqdtMgKxvCHuyi51KOPqOrZx7DNlOmupAC9D06IuJ9/pyplULushRxPcjm9fi0CV1mFYkvyVvjRNdA2B42Pl6toxSGwx1zg3tXjJWiRMEAqriR0BHOXKtw3TJU0LJtX7Z3D/2ZO4Tvwy97YewIojft+503dnfvVoD6YKiATHWfatjVbJqydYiyFzx/0BTKM5s4Gxl0d3jUmdzPg7hO41P/3cyRs1GeY5kTS4v4tjxSzE5IbPOmfFOM11zlx+XJz0YEKXfU0LldYlXnJKh3UirFaZHNi7ZB8zRetqkHuJnrBKPpy+XWBmuROACwVEXMbm85vt4iLFafVJgxrDgRvbSagzLQI8MSvlsPON081VBeQFyHPvhTsoY2km18efLWYxZCEbT02yvmKc95RkL57dnmsMiMUQBr7+jbvBlMeKgLtSsNHPkokGTzw=="; // 16字节密钥
        SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(), "AES");

        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
        cipher.init(Cipher.DECRYPT_MODE, secretKey);
        byte[] decryptedBytes = cipher.doFinal(decodedBytes);

        System.out.println("解密后的内容: " + new String(decryptedBytes));
    }
}
